package com.example;

import com.example.controller.UserController;
import com.example.repository.UserRepository;
import com.example.repository.UserRepositoryImpl;
import com.example.service.UserService;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.apache.ibatis.io.Resources;

import java.io.IOException;
import java.io.Reader;

public class Main {
    private static SqlSessionFactory sqlSessionFactory;

    static {
        try {
            String resource = "mybatis-config.xml";
            Reader reader = Resources.getResourceAsReader(resource);
            sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        // 初始化分层架构
        UserRepository userRepository = new UserRepositoryImpl(sqlSessionFactory);
        UserService userService = new UserService(userRepository);
        UserController userController = new UserController(userService);

        // 启动程序
       // userController.start();
    }
}